package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocRewardDao;
import com.irdstudio.cdp.pboc.service.domain.PbocReward;
import com.irdstudio.cdp.pboc.service.facade.PbocRewardService;
import com.irdstudio.cdp.pboc.service.vo.PbocRewardVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 行政奖励记录 				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocRewardService")
public class PbocRewardServiceImpl implements PbocRewardService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocRewardServiceImpl.class);

	@Autowired
	private PbocRewardDao pbocRewardDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocReward(PbocRewardVO inPbocRewardVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocRewardVo.toString());
		int num = 0;
		try {
			PbocReward pbocReward = new PbocReward();
			beanCopy(inPbocRewardVo, pbocReward);
			num = pbocRewardDao.insertPbocReward(pbocReward);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocRewardVO inPbocRewardVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocRewardVo);
		int num = 0;
		try {
			PbocReward pbocReward = new PbocReward();
			beanCopy(inPbocRewardVo, pbocReward);
			num = pbocRewardDao.deleteByPk(pbocReward);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocRewardVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocRewardVO inPbocRewardVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocRewardVo.toString());
		int num = 0;
		try {
			PbocReward pbocReward = new PbocReward();
			beanCopy(inPbocRewardVo, pbocReward);
			num = pbocRewardDao.updateByPk(pbocReward);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocRewardVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocRewardVO queryByPk(PbocRewardVO inPbocRewardVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocRewardVo);
		try {
			PbocReward queryPbocReward = new PbocReward();
			beanCopy(inPbocRewardVo, queryPbocReward);
			PbocReward queryRslPbocReward = pbocRewardDao.queryByPk(queryPbocReward);
			if (Objects.nonNull(queryRslPbocReward)) {
				PbocRewardVO outPbocRewardVo = beanCopy(queryRslPbocReward, new PbocRewardVO());
				logger.debug("当前查询结果为:"+ outPbocRewardVo.toString());
				return outPbocRewardVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocRewardVO> queryAllOwner(PbocRewardVO pbocRewardVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocRewardVO> list = null;
		try {
			List<PbocReward> pbocRewards = pbocRewardDao.queryAllOwnerByPage(pbocRewardVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocRewards.size());
			pageSet(pbocRewards, pbocRewardVo);
			list = (List<PbocRewardVO>) beansCopy(pbocRewards, PbocRewardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocRewardVO> queryAllCurrOrg(PbocRewardVO pbocRewardVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocReward> pbocRewards = pbocRewardDao.queryAllCurrOrgByPage(pbocRewardVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocRewards.size());
		List<PbocRewardVO> list = null;
		try {
			pageSet(pbocRewards, pbocRewardVo);
			list = (List<PbocRewardVO>) beansCopy(pbocRewards, PbocRewardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocRewardVO> queryAllCurrDownOrg(PbocRewardVO pbocRewardVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocReward> pbocRewards = pbocRewardDao.queryAllCurrDownOrgByPage(pbocRewardVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocRewards.size());
		List<PbocRewardVO> list = null;
		try {
			pageSet(pbocRewards, pbocRewardVo);
			list = (List<PbocRewardVO>) beansCopy(pbocRewards, PbocRewardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
